﻿using Ct.StudentProject.DTO;
using Ct.StudentProject.StudentModel;
using Ct.StudentProject.Repository;


namespace Ct.StudentProject.Service
{
    public class StudentService
    {
        public static RegResultDto RegStudent(RequestStudent stu)
        {
            RegResultDto rrd = new RegResultDto();  ///写入错误信息
            if (RequestStudent.VerifyAndDeliver(stu, out string errMsg) == false)
            {
                rrd.errMsg = errMsg;
                rrd.ID = 0;
                return rrd ;
            }
            else
            {
                rrd.errMsg = "correct";
                StudentToll toll = new StudentToll();      ///转换类型并写入数据库，并返回ID
                RegisterStudent user = toll.StudentTransfRegister(stu);

                //StudentRepository studentRepository
                StudentRepository db = new StudentRepository();
                int stuID = db.InsertStudent(user);
                if (stuID == 0)    //成功代号为ID，失败为0
                {
                    rrd.ID = 0;
                }
                rrd.ID = stuID;

                return rrd;
            }
            
            
        }

        //private

    }
}
